﻿@model IEnumerable<GolfLeague.ViewModels.MatchViewModel>

<fieldset>
    <legend>Matches</legend>
@if (Model.Count() == 0)
{
    <h4>No matches exist for this round.</h4>
}
else
{
    <table>
        <tr>
            <th>Match Time</th>
            <th>Team A</th>
            <th>Team B</th>
        </tr>
@foreach (var item in Model) {
        <tr>
            <td>
                @if (item.MatchTime.Hour < 12)
                {
                    @String.Format("{0:h':'mm} {1}", item.MatchTime, "AM")
                }
                else
                {
                    @String.Format("{0:h':'mm} {1}", item.MatchTime.Subtract(new TimeSpan(12,0,0)), "PM")
                }
            </td>
            <td>
                @item.Team1.TeamName<br />
                (@item.Team1.PlayerTeams.Where(t => t.TeamID == item.Team1.TeamID).First().Player.LastName/@item.Team1.PlayerTeams.Where(t => t.TeamID == item.Team1.TeamID).Last().Player.LastName)
            </td>
            <td>
                @item.Team2.TeamName<br />
                (@item.Team2.PlayerTeams.Where(t => t.TeamID == item.Team2.TeamID).First().Player.LastName/@item.Team2.PlayerTeams.Where(t => t.TeamID == item.Team2.TeamID).Last().Player.LastName)
            </td>
        </tr>
}
    </table>
}
</fieldset>